/**
 *  StaDiUM - State Diagram Unified Modeler
 *  Copyright (C) 2007  Stefan Bucur, Mihai Balan, Claudiu Tanase
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.

 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.

 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

/**
 *  File Information
 *
 *  Last Modified On: $Date: 2007-05-28 22:50:32 +0000 (Mon, 28 May 2007) $
 *  Last Modified By: $Author: stefan.bucur $
 */

package ro.pub.cs.stadium.platform;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;

/**
 * Manages the creation and configuration of the main menu
 * @author stefan
 *
 */
public class MenuManager {
	private Menu menuBar = null;
	
	private Shell wndShell = null;
	
	private SelectionListener defaultList = null;
	
	// MenuItems
	private Menu	 newM = null;
	private MenuItem openMI = null;
	private MenuItem saveMI = null;
	private MenuItem printMI = null;
	
	private MenuItem aboutMI = null;
	private MenuItem exitMI = null;
	private MenuItem preferencesMI = null;
	
	/**
	 * Creates the general menu items, independent of the
	 * document type 
	 *
	 */
	private void createPlatformItems() {
		///////////////////////////////
		// The File menu
		MenuItem fileMI = new MenuItem(menuBar, SWT.CASCADE);
		fileMI.setText("&File");
		
			Menu fileM = new Menu(wndShell, SWT.DROP_DOWN);
			fileMI.setMenu(fileM);
			
			newM = new Menu(wndShell, SWT.DROP_DOWN);
			MenuItem newMI = new MenuItem(fileM, SWT.CASCADE);
			newMI.setText("&New");
			newMI.setMenu(newM);
			
			openMI = new MenuItem(fileM, SWT.PUSH);
			openMI.setText("&Open...");
			openMI.addSelectionListener(defaultList);
			
			new MenuItem(fileM, SWT.SEPARATOR);
			
			saveMI = new MenuItem(fileM, SWT.PUSH);
			saveMI.setText("&Save");
			saveMI.addSelectionListener(defaultList);
			
			new MenuItem(fileM, SWT.SEPARATOR);
			
			printMI = new MenuItem(fileM, SWT.PUSH);
			printMI.setText("&Print...");
			printMI.addSelectionListener(defaultList);
			
			new MenuItem(fileM, SWT.SEPARATOR);
			
			
			
			exitMI = new MenuItem(fileM, SWT.PUSH);
			exitMI.setText("E&xit");
			exitMI.addSelectionListener(defaultList);
		
		///////////////////////////////
		// The Edit menu
		MenuItem editMI = new MenuItem(menuBar, SWT.CASCADE);
		editMI.setText("&Edit");
		
			Menu editM = new Menu(wndShell, SWT.DROP_DOWN);
			editMI.setMenu(editM);
			
		///////////////////////////////
		// The Diagram menu
		MenuItem diagramMI = new MenuItem(menuBar, SWT.CASCADE);
		diagramMI.setText("&Diagram");
		
			Menu diagramM = new Menu(wndShell, SWT.DROP_DOWN);
			diagramMI.setMenu(diagramM);
		
		///////////////////////////////
		// The Window menu
		MenuItem windowMI = new MenuItem(menuBar, SWT.CASCADE);
		windowMI.setText("&Window");
		
			Menu windowM = new Menu(wndShell, SWT.DROP_DOWN);
			windowMI.setMenu(windowM);
			
			new MenuItem(windowM, SWT.SEPARATOR);
			
			preferencesMI = new MenuItem(windowM, SWT.PUSH);
			preferencesMI.setText("&Preferences...");
			preferencesMI.addSelectionListener(defaultList);
			
			
			
		
		///////////////////////////////
		// The Help menu
		MenuItem helpMI = new MenuItem(menuBar, SWT.CASCADE);
		helpMI.setText("&Help");
		
			Menu helpM = new Menu(wndShell, SWT.DROP_DOWN);
			helpMI.setMenu(helpM);
			
			aboutMI = new MenuItem(helpM, SWT.PUSH);
			aboutMI.setText("&About StaDiUM...");
			aboutMI.addSelectionListener(defaultList);
		
	}
	
	// PUBLIC METHODS
	
	public MenuManager(Menu menuBar, SelectionListener defaultList) {
		this.menuBar = menuBar;
		this.defaultList = defaultList;
		
		wndShell = menuBar.getShell();
	}
	
	public void populateMenuBar() {
		createPlatformItems();
	}
	
	public Menu getMenuBar() {
		return menuBar;
	}
	
	// Menu Items Getters
	
	public MenuItem getAboutMenuItem() {
		return aboutMI;
	}
	
	public MenuItem getExitMenuItem() {
		return exitMI;
	}
	
	public MenuItem getPreferencesMenuItem() {
		return preferencesMI;
	}
	
	public Menu getNewMenu() {
		return newM;
	}
	
	public MenuItem getOpenMenuItem() {
		return openMI;
	}
	
	public MenuItem getSaveMenuItem() {
		return saveMI;
	}
	
	public MenuItem getPrintMenuItem() {
		return printMI;
	}
}
